home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GADGETS.PAK / GADGETS.CPP next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  196 lines

  1. // ---------------------------------------------------------------------------
  2. // Copyright (C) 1995, 1995 Borland International
  3. // ---------------------------------------------------------------------------
  4. #include <owl/pch.h>
  5. #include <owl/controlb.h>
  6. #include <owl/statusba.h>
  7. #include <owl/menugadg.h>
  8. #include <owl/timegadg.h>
  9. #include <owl/modegad.h>
  10. #include <owl/controlg.h>
  11. #include <owl/buttonga.h>
  12. #include <owl/edit.h>
  13. #include "gadgets.rh"
  14.  
  15. const int EditId = 10001;
  16. TEdit* GlobalEdit;
  17. TMenuGadget* MenuGadget;
  18. TTextGadget* TextGadget;
  19.  
  20. class TMyControlBar : public TControlBar {
  21.   public:
  22.     TMyControlBar(TWindow*        parent = 0,
  23.                   TTileDirection  direction = Horizontal,
  24.                   TFont*          font = new TGadgetWindowFont,
  25.                   TModule*        module = 0)
  26.     :
  27.       TControlBar(parent, direction, font, module)
  28.     {
  29.     }
  30.  
  31.     void EnUpdate()
  32.     {
  33.       GetApplication()->GetMainWindow()->GetClientWindow()->Invalidate();
  34.     }
  35.  
  36.   DECLARE_RESPONSE_TABLE(TMyControlBar);
  37. };
  38.  
  39. DEFINE_RESPONSE_TABLE1(TMyControlBar, TControlBar)
  40.   EV_EN_UPDATE(EditId, EnUpdate),
  41. END_RESPONSE_TABLE;
  42.  
  43.  
  44. //
  45. // TTestWindow
  46. // ~~~~~~~~~~~
  47. class TTestWindow : public TWindow {
  48.   public:
  49.     TTestWindow() : TWindow(0, 0, 0) { Item2Active = false; }
  50.  
  51.     void CmItem1()
  52.     {
  53.       MenuGadget->SetText("Item 1");
  54.       Item2Active = !Item2Active;
  55.     }
  56.  
  57.     void CmItem2()
  58.     {
  59.       MenuGadget->SetText("Item 2");
  60.       MessageBox("Thank you", "Item 2", MB_OK);
  61.     }
  62.  
  63.     void CeItem2(TCommandEnabler& ce) { ce.Enable(Item2Active); }
  64.  
  65.     void CmItem3()
  66.     {
  67.       MenuGadget->SetText("This is an Item 3");
  68.       MessageBox("Thank you", "Item 3", MB_OK);
  69.     }
  70.  
  71.     void Paint(TDC& dc, bool, TRect&)
  72.     {
  73.       if (GlobalEdit) {
  74.         int len = GlobalEdit->GetTextLen();
  75.         if (len > 0) {
  76.           char* buffer = new char[len+1];
  77.           GlobalEdit->GetText(buffer, len+1);
  78.           TRect r = GetClientRect();
  79.           dc.DrawText(buffer, len, r, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
  80.           delete[] buffer;
  81.         }
  82.       }
  83.     }
  84.  
  85.     void CmHappy()
  86.     {
  87.       ::MessageBeep(-1);
  88.     }
  89.  
  90.     void EvLButtonDown(uint modKeys, TPoint& point)
  91.     {
  92.       SetFocus();
  93.     }
  94.  
  95.     bool Item2Active;
  96.  
  97.   DECLARE_RESPONSE_TABLE(TTestWindow);
  98. };
  99.  
  100. DEFINE_RESPONSE_TABLE1(TTestWindow, TWindow)
  101.   EV_WM_LBUTTONDOWN,
  102.   EV_COMMAND(CM_ITEM1, CmItem1),
  103.   EV_COMMAND(CM_ITEM2, CmItem2),
  104.   EV_COMMAND_ENABLE(CM_ITEM2, CeItem2),
  105.   EV_COMMAND(CM_ITEM3, CmItem3),
  106.   EV_COMMAND(ID_HAPPY, CmHappy),
  107. END_RESPONSE_TABLE;
  108.  
  109. //
  110. // TTestApplication
  111. // ~~~~~~~~~~~~~~~~
  112. class TTestApp : public TApplication {
  113.   public:
  114.     TTestApp() {
  115.     }
  116.  
  117.    ~TTestApp() {
  118.     }
  119.  
  120.     void InitMainWindow();
  121.  
  122.     TMyControlBar* ControlBar;
  123.     TStatusBar*    StatusBar;
  124. };
  125.  
  126. void
  127. TTestApp::InitMainWindow()
  128. {
  129.   TWindow* testWindow = new TTestWindow;
  130.   TDecoratedFrame* frame = new TDecoratedFrame(0, "Test application", testWindow, true);
  131.  
  132.   // decorations
  133.   //
  134.   ControlBar = new TMyControlBar(frame);
  135.   frame->Insert(*ControlBar, TDecoratedFrame::Top);
  136.   TMenu menu(*this, "TRACKMENU");
  137.   MenuGadget = new TMenuGadget(menu, frame);
  138.   ControlBar->Insert(*new TButtonGadget(ID_HAPPY, ID_HAPPY));
  139.   ControlBar->Insert(*new TSeparatorGadget);
  140.  
  141.   ControlBar->Insert(*MenuGadget);
  142.   ControlBar->Insert(*new TSeparatorGadget);
  143.   ControlBar->Insert(*new TModeGadget(VK_LEFT, "Left"));
  144.  
  145.   TGadget* gadget = new TSeparatorGadget;
  146.   gadget->WideAsPossible = true;
  147.   ControlBar->Insert(*gadget);
  148.  
  149.   ControlBar->Insert(*new TModeGadget(VK_RIGHT, "Right"));
  150.   ControlBar->Insert(*new TSeparatorGadget);
  151.   TextGadget = new TTextGadget(0, TGadget::Recessed, TTextGadget::Left, 8);
  152.   TextGadget->SetText("WWWWWWW");
  153.   ControlBar->Insert(*TextGadget);
  154.   TextGadget->SetEnabled(false);
  155.  
  156.   ControlBar->Insert(*new TSeparatorGadget);
  157.   GlobalEdit = new TEdit(0, EditId, "", 0, 0, 150, 25);
  158.   ControlBar->Insert(*new TControlGadget(*GlobalEdit));
  159.  
  160.   StatusBar = new TStatusBar(frame);
  161.   StatusBar->Insert(*new TSeparatorGadget);
  162.   StatusBar->Insert(*new TModeGadget(VK_UP, "Up"));
  163.   StatusBar->Insert(*new TSeparatorGadget);
  164.   StatusBar->Insert(*new TModeGadget(VK_DOWN, "Down"));
  165.   StatusBar->Insert(*new TSeparatorGadget);
  166.   StatusBar->Insert(*new TModeGadget(VK_NUMLOCK, "Num"));
  167.   StatusBar->Insert(*new TSeparatorGadget);
  168.   StatusBar->Insert(*new TModeGadget(VK_INSERT, "Ins"));
  169.   StatusBar->Insert(*new TSeparatorGadget);
  170.   StatusBar->Insert(*new TModeGadget(VK_SCROLL, "Scr"));
  171.   StatusBar->Insert(*new TSeparatorGadget);
  172.  
  173.   StatusBar->Insert(*new TTimeGadget);
  174. #if defined(BI_PLAT_WIN32)
  175.   StatusBar->Insert(*new TTimeGadget(&TTimeGadget::GetSystemTime));
  176. #endif
  177.   frame->Insert(*StatusBar, TDecoratedFrame::Bottom);
  178.  
  179.   SetMainWindow(frame);
  180. }
  181.  
  182. int
  183. OwlMain(int /*argc*/, char* /*argv*/ [])
  184. {
  185.   int retVal = 0;
  186.   try {
  187.     TTestApp app;
  188.     retVal = app.Run();
  189.   }
  190.   catch (...) {
  191.     ::MessageBeep(-1);
  192.   }
  193.   return retVal;
  194. }
  195.  
  196.